package com.kingdee.eas.hr.emp.client;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.kdf.table.ICell;
import com.kingdee.bos.ctrl.kdf.table.IColumn;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTDefaultCellEditor;
import com.kingdee.bos.ctrl.kdf.table.KDTSelectBlock;
import com.kingdee.bos.ctrl.kdf.table.KDTSortManager;
import com.kingdee.bos.ctrl.kdf.table.KDTTransferAction;
import com.kingdee.bos.ctrl.kdf.table.event.BeforeActionEvent;
import com.kingdee.bos.ctrl.kdf.table.event.BeforeActionListener;
import com.kingdee.bos.ctrl.kdf.table.event.KDTEditAdapter;
import com.kingdee.bos.ctrl.kdf.table.event.KDTEditEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTPropertyChangeEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTPropertyChangeListener;
import com.kingdee.bos.ctrl.kdf.table.event.KDTSelectEvent;
import com.kingdee.bos.ctrl.kdf.util.editor.ICellEditor;
import com.kingdee.bos.ctrl.kdf.util.style.StyleAttributes;
import com.kingdee.bos.ctrl.swing.KDCheckBox;
import com.kingdee.bos.ctrl.swing.KDComboBox;
import com.kingdee.bos.ctrl.swing.KDDatePicker;
import com.kingdee.bos.ctrl.swing.KDFormattedTextField;
import com.kingdee.bos.ctrl.swing.KDTextField;
import com.kingdee.bos.ctrl.swing.event.DataChangeEvent;
import com.kingdee.bos.ctrl.swing.event.DataChangeListener;
import com.kingdee.bos.ctrl.swing.event.PreChangeEvent;
import com.kingdee.bos.ctrl.swing.event.PreChangeListener;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.metadata.entity.SorterItemInfo;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory;
import com.kingdee.eas.base.codingrule.ICodingRuleManager;
import com.kingdee.eas.base.param.util.ParamManager;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.org.CtrlUnitInfo;
import com.kingdee.eas.basedata.org.HROrgUnitInfo;
import com.kingdee.eas.basedata.org.OrgType;
import com.kingdee.eas.basedata.org.PositionInfo;
import com.kingdee.eas.basedata.org.client.f7.AdminF7;
import com.kingdee.eas.basedata.person.IPerson;
import com.kingdee.eas.basedata.person.PersonCollection;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.OprtState;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.framework.DataBaseCollection;
import com.kingdee.eas.framework.FrameWorkUtils;
import com.kingdee.eas.framework.IDataBase;
import com.kingdee.eas.hr.affair.client.OrgFullNameRender;
import com.kingdee.eas.hr.base.util.HRParamUtil;
import com.kingdee.eas.hr.base.util.HRUtil;
import com.kingdee.eas.hr.emp.ContractLimitFactory;
import com.kingdee.eas.hr.emp.ContractLimitInfo;
import com.kingdee.eas.hr.emp.ContractLimitTypeEnum;
import com.kingdee.eas.hr.emp.ContractServerLimitFactory;
import com.kingdee.eas.hr.emp.ContractServerLimitInfo;
import com.kingdee.eas.hr.emp.ContractTempletCollection;
import com.kingdee.eas.hr.emp.ContractTempletFactory;
import com.kingdee.eas.hr.emp.ContractTempletInfo;
import com.kingdee.eas.hr.emp.ContractTypeInfo;
import com.kingdee.eas.hr.emp.EmployeeContractCollection;
import com.kingdee.eas.hr.emp.EmployeeContractFactory;
import com.kingdee.eas.hr.emp.EmployeeContractInfo;
import com.kingdee.eas.hr.emp.EmployeeContractState;
import com.kingdee.eas.hr.emp.EmployeeException;
import com.kingdee.eas.hr.emp.IContractLimit;
import com.kingdee.eas.hr.emp.IContractServerLimit;
import com.kingdee.eas.hr.emp.IContractTemplet;
import com.kingdee.eas.hr.emp.IEmployeeContract;
import com.kingdee.eas.hr.emp.IPersonPosition;
import com.kingdee.eas.hr.emp.PersonPositionCollection;
import com.kingdee.eas.hr.emp.PersonPositionFactory;
import com.kingdee.eas.hr.org.client.AdminByOrgRangePromptBox;
import com.kingdee.eas.hr.org.client.AllAdminPromptBox;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.ExceptionHandler;
import com.kingdee.eas.util.client.KDTableUtil;
import com.kingdee.eas.util.client.MsgBox;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.DateTimeUtils;
import com.kingdee.util.StringUtils;
import com.kingdee.util.enums.EnumUtils;

import edu.emory.mathcs.backport.java.util.Collections;

public class BatchContractEditUI extends AbstractBatchContractEditUI {
	protected KDComboBox cboContractTemplet = new KDComboBox();

	private final Color MUST_INPUT_COLOR = new Color(252, 251, 223);

	private final Color CANNOT_INPUT_COLOR = new Color(208, 208, 208);
	private final Color CAN_INPUT_COLOR = new Color(255, 255, 255);

	int rowID = -1;
	int colID = -1;
	public Vector pks = null;

	String oldTypeID = null;

	private EmployeeContractInfo newInfo = new EmployeeContractInfo();
	private ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory
			.getRemoteInstance();

	private String appOUID = null;
	private boolean isExistCodingRule = false;

	boolean isZTCustomer = false;

	boolean isBatchProcess = false;

	protected boolean isSaved = false;

	private boolean isStrideHRO = false;
	private boolean isShowLongName = false;

	final KDBizPromptBox promptToUnitBox = new KDBizPromptBox();
	final KDCheckBox chkIsAdmin = new KDCheckBox();

	private boolean theFirst = true;

	public BatchContractEditUI() throws Exception {
		this.isZTCustomer = EmployeeContractFactory.getRemoteInstance()
				.isZhongTianCustomer();

		initKDTPropertyChangeListener();
	}

	protected void initUserConfig() {
		super.initUserConfig();

		Object obj = this.cboProcessType.getSelectedItem();

		if ((!EmployeeContractState.RESUME.equals(obj))
				&& (!EmployeeContractState.CHANGE.equals(obj))) {
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(true);
			this.tHelper.getHideColumn().add("contractNoOld");
		}
	}

	void setTableCellEditor() throws Exception {
		KDTextField txtContractNo = new KDTextField();
		txtContractNo.setMaxLength(80);
		if (this.isExistCodingRule) {
			if (!this.isBatchProcess) {
				this.tblContract.getColumn("contractNo").getStyleAttributes()
						.setHided(true);
			}
		}
		this.tblContract.getColumn("contractNo").setEditor(
				new KDTDefaultCellEditor(txtContractNo));

		KDTextField txtToUnitAddress = new KDTextField();
		txtToUnitAddress.setMaxLength(160);
		this.tblContract.getColumn("toUnitAddress").setEditor(
				new KDTDefaultCellEditor(txtToUnitAddress));

		this.tblContract.getColumn("contractNo").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		this.tblContract.getColumn("recordDate").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);
		this.tblContract.getColumn("effectDate").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		HashSet set = new HashSet();
		set.add(getCurrentHRO().getId().toString());

		EmployeeMultiF7PromptBox personPrmt = new EmployeeMultiF7PromptBox();
		personPrmt.setIsSingleSelect(true);
		if (this.isZTCustomer) {
			personPrmt.setIsShowAllAdmin(true);
		} else if (this.isStrideHRO)
			personPrmt.setIsShowAllAdmin(true);
		else {
			personPrmt.setHROFilter(set);
		}

		personPrmt.showNoPositionPerson(true);
		KDBizPromptBox promptPersonBox = new KDBizPromptBox();
		promptPersonBox.setSelector(personPrmt);
		promptPersonBox.setDisplayFormat("$name$");
		promptPersonBox.setEditFormat("$number$");
		promptPersonBox.setCommitFormat("$number$");
		promptPersonBox.setEditable(false);
		this.tblContract.getColumn("person").setEditor(
				new KDTDefaultCellEditor(promptPersonBox));
		this.tblContract.getColumn("person").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		lockColumnWithKey("empNumber");
		lockColumnWithKey("empUnit");
		lockColumnWithKey("empPosition");

		KDBizPromptBox promptDelegatePersonBox = new KDBizPromptBox();
		setToUnitPromtRange(this.promptToUnitBox, promptDelegatePersonBox);
		if (getUIContext().get("isInAdmin") == null) {
			this.tblContract.getColumn("toUnit").setEditor(
					new KDTDefaultCellEditor(this.promptToUnitBox));
		} else if (((Boolean) getUIContext().get("isInAdmin")).booleanValue())
			this.tblContract.getColumn("toUnit").setEditor(
					new KDTDefaultCellEditor(this.promptToUnitBox));
		else {
			this.tblContract.getColumn("toUnit").setEditor(
					new KDTDefaultCellEditor(new KDTextField()));
		}

		this.chkIsAdmin.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				Object isInAdmin = BatchContractEditUI.this.tblContract
						.getCell(
								BatchContractEditUI.this.tblContract
										.getSelectManager().getActiveRowIndex(),
								BatchContractEditUI.this.tblContract
										.getSelectManager()
										.getActiveColumnIndex()).getValue();

				if (new Boolean(false).equals(isInAdmin))
					BatchContractEditUI.this.tblContract.getCell(
							BatchContractEditUI.this.tblContract
									.getSelectManager().getActiveRowIndex(),
							BatchContractEditUI.this.tblContract
									.getColumnIndex("toUnit")).setValue(null);
			}
		});
		this.tblContract.getColumn("isInAdmin").setEditor(
				new KDTDefaultCellEditor(this.chkIsAdmin));

		if (this.isShowLongName) {
			this.promptToUnitBox.setDisplayFormat("$displayName$");
			this.promptToUnitBox.setEditFormat("$displayName$");
			this.promptToUnitBox.setCommitFormat("$displayName$");
			this.tblContract.getColumn("toUnit").setRenderer(
					new OrgFullNameRender());
		} else {
			this.promptToUnitBox.setDisplayFormat("$name$");
			this.promptToUnitBox.setEditFormat("$name$");
			this.promptToUnitBox.setCommitFormat("$name$");
		}
		this.promptToUnitBox.setEditable(false);
		this.tblContract.getColumn("toUnit").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		promptDelegatePersonBox.setDisplayFormat("$name$");
		promptDelegatePersonBox.setEditFormat("$number$");
		promptDelegatePersonBox.setCommitFormat("$number$");
		promptDelegatePersonBox.setEditable(false);
		this.tblContract.getColumn("delegatePerson").setEditor(
				new KDTDefaultCellEditor(promptDelegatePersonBox));

		KDBizPromptBox promptContractTypeBox = new KDBizPromptBox();
		ContractTypePromptBox contractTypePromptBox = new ContractTypePromptBox(
				this);
		HashSet cuSet = new HashSet();
		cuSet.add(getCurrentCU());
		contractTypePromptBox.setCUs(cuSet);

		promptContractTypeBox.setSelector(contractTypePromptBox);

		promptContractTypeBox.setDisplayFormat("$name$");
		promptContractTypeBox.setEditFormat("$number$");
		promptContractTypeBox.setCommitFormat("$number$");
		promptContractTypeBox.setEditable(false);
		promptContractTypeBox.addDataChangeListener(new DataChangeListener() {
			public void dataChanged(DataChangeEvent eventObj) {
				ContractTypeInfo contractType = (eventObj.getNewValue() instanceof ContractTypeInfo) ? (ContractTypeInfo) eventObj
						.getNewValue()
						: null;

				StyleAttributes styleAttributes = null;
				if ((contractType != null)
						&& (contractType.isIsLaborContract())) {
					styleAttributes = BatchContractEditUI.this.tblContract
							.getRow(BatchContractEditUI.this.rowID).getCell(
									"isContinuousSigned").getStyleAttributes();
					styleAttributes.setLocked(false);
					styleAttributes
							.setBackground(BatchContractEditUI.this.CAN_INPUT_COLOR);
					styleAttributes = BatchContractEditUI.this.tblContract
							.getRow(BatchContractEditUI.this.rowID).getCell(
									"continuousSignedCount")
							.getStyleAttributes();
					styleAttributes.setLocked(false);
					styleAttributes
							.setBackground(BatchContractEditUI.this.CAN_INPUT_COLOR);
				} else {
					BatchContractEditUI.this.tblContract.getRow(
							BatchContractEditUI.this.rowID).getCell(
							"isContinuousSigned").setValue(
							Boolean.valueOf(false));
					BatchContractEditUI.this.tblContract.getRow(
							BatchContractEditUI.this.rowID).getCell(
							"continuousSignedCount").setValue(new Integer(0));

					styleAttributes = BatchContractEditUI.this.tblContract
							.getRow(BatchContractEditUI.this.rowID).getCell(
									"isContinuousSigned").getStyleAttributes();
					styleAttributes.setLocked(false);
					styleAttributes
							.setBackground(BatchContractEditUI.this.CANNOT_INPUT_COLOR);
					styleAttributes = BatchContractEditUI.this.tblContract
							.getRow(BatchContractEditUI.this.rowID).getCell(
									"continuousSignedCount")
							.getStyleAttributes();
					styleAttributes.setLocked(true);
					styleAttributes
							.setBackground(BatchContractEditUI.this.CANNOT_INPUT_COLOR);
				}
			}
		});
		this.tblContract.getColumn("contractTypeName").setEditor(
				new KDTDefaultCellEditor(promptContractTypeBox));
		this.tblContract.getColumn("contractTypeName").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		this.tblContract.getColumn("contractTempletName").setEditor(
				new KDTDefaultCellEditor(this.cboContractTemplet));
		this.tblContract.getColumn("contractTempletName").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		KDDatePicker dpDate = new KDDatePicker();
		dpDate.setValue(new Date());
		this.tblContract.getColumn("recordDate").setEditor(
				new KDTDefaultCellEditor(dpDate));
		this.tblContract.getColumn("recordDate").getStyleAttributes()
				.setNumberFormat(EmployeeClientUtils.getDateFormatStr());
		this.tblContract.getColumn("recordDate").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		this.tblContract.getColumn("effectDate").setEditor(
				new KDTDefaultCellEditor(dpDate));
		this.tblContract.getColumn("effectDate").getStyleAttributes()
				.setNumberFormat(EmployeeClientUtils.getDateFormatStr());
		this.tblContract.getColumn("effectDate").getStyleAttributes()
				.setBackground(this.MUST_INPUT_COLOR);

		GregorianCalendar cal = new GregorianCalendar(2199, 11, 31);
		dpDate.setValue(cal.getTime());
		this.tblContract.getColumn("endDate").setEditor(
				new KDTDefaultCellEditor(dpDate));
		this.tblContract.getColumn("endDate").getStyleAttributes()
				.setNumberFormat(EmployeeClientUtils.getDateFormatStr());

		this.tblContract.getColumn("freeDate").setEditor(
				new KDTDefaultCellEditor(dpDate));
		this.tblContract.getColumn("freeDate").getStyleAttributes()
				.setNumberFormat(EmployeeClientUtils.getDateFormatStr());
		lockColumnWithKey("freeDate");

		dpDate.addDataChangeListener(new DataChangeListener() {
			public void dataChanged(DataChangeEvent e) {
				Object effectDate = BatchContractEditUI.this.tblContract
						.getRow(BatchContractEditUI.this.rowID).getCell(
								"effectDate").getValue();
				Object endDate = BatchContractEditUI.this.tblContract.getRow(
						BatchContractEditUI.this.rowID).getCell("endDate")
						.getValue();
				if (BatchContractEditUI.this.tblContract
						.getColumn("effectDate").getColumnIndex() == BatchContractEditUI.this.colID) {
					effectDate = e.getNewValue();
				}
				if (BatchContractEditUI.this.tblContract.getColumn("endDate")
						.getColumnIndex() == BatchContractEditUI.this.colID) {
					endDate = e.getNewValue();
				}

				BatchContractEditUI.this.fixContractLimitAuto(effectDate,
						endDate);
			}
		});
		EntityViewInfo view = new EntityViewInfo();
		FilterInfo filter = new FilterInfo();

		view.setFilter(filter);
		view.getSorter().add(new SorterItemInfo("number"));

		KDComboBox cboContractLimit = new KDComboBox();
		IContractLimit iContLimit = ContractLimitFactory.getRemoteInstance();
		initComboboxItemData(cboContractLimit, iContLimit, view);
		this.tblContract.getColumn("contractLimit").setEditor(
				new KDTDefaultCellEditor(cboContractLimit));

		KDComboBox cboConSrvLimit = new KDComboBox();
		IContractServerLimit iContSrvLimit = ContractServerLimitFactory
				.getRemoteInstance();
		initComboboxItemData(cboConSrvLimit, iContSrvLimit, view);
		this.tblContract.getColumn("contSrvLimit").setEditor(
				new KDTDefaultCellEditor(cboConSrvLimit));

		this.tblContract.getColumn("testBeginDate").setEditor(
				new KDTDefaultCellEditor(new KDDatePicker()));
		this.tblContract.getColumn("testBeginDate").getStyleAttributes()
				.setNumberFormat(EmployeeClientUtils.getDateFormatStr());
		this.tblContract.getColumn("testEndDate").setEditor(
				new KDTDefaultCellEditor(new KDDatePicker()));
		this.tblContract.getColumn("testEndDate").getStyleAttributes()
				.setNumberFormat(EmployeeClientUtils.getDateFormatStr());

		KDTextField txtThirdUnitName = new KDTextField();
		txtContractNo.setMaxLength(80);
		this.tblContract.getColumn("thirdUnitName").setEditor(
				new KDTDefaultCellEditor(txtThirdUnitName));

		KDTextField txtThirdDelegatePerson = new KDTextField();
		txtContractNo.setMaxLength(80);
		this.tblContract.getColumn("thirdDelegatePerson").setEditor(
				new KDTDefaultCellEditor(txtThirdDelegatePerson));

		KDTextField txtThirdUnitAddress = new KDTextField();
		txtContractNo.setMaxLength(80);
		this.tblContract.getColumn("thirdUnitAddress").setEditor(
				new KDTDefaultCellEditor(txtThirdUnitAddress));

		KDComboBox cboContractLimitType = new KDComboBox();
		cboContractLimitType.addItems(EnumUtils.getEnumList(
				"com.kingdee.eas.hr.emp.ContractLimitTypeEnum").toArray());
		this.tblContract.getColumn("contractLimitType").setEditor(
				new KDTDefaultCellEditor(cboContractLimitType));
		cboContractLimitType.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				BatchContractEditUI.this
						.refreshStatusByContractLimitType(((KDComboBox) e
								.getSource()).getSelectedItem());
			}
		});
		lockColumnWithKey("employeeClassify");
		lockColumnWithKey("contractLimitAuto");

		this.tblContract.addKDTEditListener(new KDTEditAdapter() {
			public void editStarting(KDTEditEvent e) {
				BatchContractEditUI.this.rowID = e.getRowIndex();
				BatchContractEditUI.this.colID = e.getColIndex();
				try {
					if (BatchContractEditUI.this.tblContract.getColumn(
							e.getColIndex()).getKey().toUpperCase().equals(
							"contractTempletName".toUpperCase())) {
						Object obj = BatchContractEditUI.this.tblContract
								.getRow(BatchContractEditUI.this.rowID)
								.getCell("contractTypeName").getValue();
						if (obj != null)
							BatchContractEditUI.this
									.loadContractTempletComboData(((ContractTypeInfo) obj)
											.getId().toString());
						else {
							BatchContractEditUI.this.cboContractTemplet
									.removeAllItems();
						}
					}
				} catch (Exception e1) {
					ExceptionHandler.handle(e1);
				}
			}
		});
		promptPersonBox.addPreChangeListener(new PreChangeListener() {
			public void preChange(PreChangeEvent e) {
				if ((e.getData() != null)
						&& ((e.getData() instanceof PersonInfo))) {
					try {
						PersonInfo personInfo = (PersonInfo) e.getData();
						BatchContractEditUI.this.tblContract.getRow(
								BatchContractEditUI.this.rowID).getCell(
								"empNumber").setValue(personInfo.getNumber());
						IPerson iPerson = PersonFactory.getRemoteInstance();

						String name = null;
						AdminOrgUnitInfo unitInfo = BatchContractEditUI.this
								.getPersonDep(personInfo);
						if (unitInfo != null) {
							name = unitInfo.getName();
						}
						BatchContractEditUI.this.tblContract.getRow(
								BatchContractEditUI.this.rowID).getCell(
								"empUnit").setValue(name);

						PositionInfo posInfo = iPerson
								.getPrimaryPosition(personInfo.getId());
						name = null;
						if (posInfo != null) {
							name = posInfo.getName();
						}
						BatchContractEditUI.this.tblContract.getRow(
								BatchContractEditUI.this.rowID).getCell(
								"empPosition").setValue(name);
					} catch (Exception e1) {
						ExceptionHandler.handle(e1);
					}
				} else {
					IRow currentRow = BatchContractEditUI.this.tblContract
							.getRow(BatchContractEditUI.this.rowID);
					currentRow.getCell("empNumber").setValue(null);
					currentRow.getCell("empUnit").setValue(null);
					currentRow.getCell("empPosition").setValue(null);
				}
			}
		});
		promptContractTypeBox.addPreChangeListener(new PreChangeListener() {
			public void preChange(PreChangeEvent e) {
				try {
					ComboBoxModel model = null;
					if (e.getData() != null) {
						model = BatchContractEditUI.this
								.getContractTempletComboModel(((ContractTypeInfo) e
										.getData()).getId().toString());
					}
					if (model == null) {
						model = new DefaultComboBoxModel();
					}
					BatchContractEditUI.this.cboContractTemplet.setModel(model);
					BatchContractEditUI.this.tblContract.getRow(
							BatchContractEditUI.this.rowID).getCell(
							"contractTempletName").setValue(null);
					BatchContractEditUI.this.tblContract
							.getRow(BatchContractEditUI.this.rowID)
							.getCell("contractTempletName")
							.setEditor(
									new KDTDefaultCellEditor(
											BatchContractEditUI.this.cboContractTemplet));
				} catch (Exception e1) {
					ExceptionHandler.handle(e1);
				}
			}
		});
		((KDTTransferAction) this.tblContract.getActionMap().get("Paste"))
				.setPasteMode(2);

		this.tblContract.getColumn("isContinuousSigned").setEditor(
				new KDTDefaultCellEditor(new KDCheckBox()));
		KDFormattedTextField textField = new KDFormattedTextField();
		textField.setPrecision(0);
		textField.setDataType(0);
		textField.setMinimumValue(new Integer(0));
		textField.setMaximumValue(new Integer(100));
		this.tblContract.getColumn("continuousSignedCount").setEditor(
				new KDTDefaultCellEditor(textField));
	}

	private void initKDTPropertyChangeListener() {
		this.tblContract
				.addKDTPropertyChangeListener(new KDTPropertyChangeListener() {
					public void propertyChange(KDTPropertyChangeEvent event) {
						String oprtState = BatchContractEditUI.this
								.getOprtState();
						if (((oprtState.equals(OprtState.ADDNEW)) || (oprtState
								.equals(OprtState.EDIT)))
								&& ((event.getNewValue() instanceof String))) {
							String newValue = (String) event.getNewValue();
							ICell cell = BatchContractEditUI.this.tblContract
									.getCell(event.getRowIndex(), event
											.getColIndex());
							if (cell == null) {
								return;
							}
							ICellEditor cellEditor = cell.getEditor();
							if (cellEditor == null) {
								cellEditor = BatchContractEditUI.this.tblContract
										.getColumn(event.getColIndex())
										.getEditor();
								if (cellEditor == null) {
									return;
								}
							}
							Component comp = cellEditor.getComponent();
							if ((comp instanceof KDComboBox)) {
								KDComboBox comboBox = (KDComboBox) comp;
								int count = comboBox.getItemCount();
								int i = 0;
								for (i = 0; i < count; i++) {
									if (newValue.equals(comboBox.getItemAt(i)
											.toString())) {
										cell.setValue(comboBox.getItemAt(i));
										break;
									}
								}
								if (i == count)
									cell.setValue(null);
							}
						}
					}
				});
	}

	private void setToUnitPromtRange(KDBizPromptBox prmtToUnit,
			KDBizPromptBox prmtDelegatePerson) {
		EmployeeMultiF7PromptBox delegatePerson = new EmployeeMultiF7PromptBox();
		delegatePerson.setIsSingleSelect(true);
		try {
			if (this.isZTCustomer) {
				prmtToUnit.setSelector(new AdminF7());
				delegatePerson.setIsShowAllAdmin(true);
				prmtDelegatePerson.setSelector(delegatePerson);
			} else {
				String contractOrgRange = ParamManager.getParamValue(null,
						new ObjectUuidPK(getCurrentHRO().getId()),
						"IS_CONTRACT_002");

				if ("0".equals(contractOrgRange)) {
					AllAdminPromptBox alladmin = new AllAdminPromptBox();
					alladmin.setIsSingleSelect(true);
					prmtToUnit.setSelector(alladmin);

					delegatePerson.setIsShowAllAdmin(true);
					prmtDelegatePerson.setSelector(delegatePerson);
				}

				if ("1".equals(contractOrgRange)) {
					AdminByOrgRangePromptBox adminPrmt = new AdminByOrgRangePromptBox(
							"true");
					HashSet set = new HashSet();
					set.add(getCurrentHRO().getId().toString());
					adminPrmt.setHROFilter(set);
					prmtToUnit.setSelector(adminPrmt);

					delegatePerson.setHROFilter(set);
					prmtDelegatePerson.setSelector(delegatePerson);
				}

				if ("2".equals(contractOrgRange)) {
					AdminByOrgRangePromptBox adminPrmt = new AdminByOrgRangePromptBox(
							"true");
					prmtToUnit.setSelector(adminPrmt);

					delegatePerson.setUserOrgRangeFilter(true);
					prmtDelegatePerson.setSelector(delegatePerson);
				}
			}

		} catch (Exception e) {
			ExceptionHandler.handle(e);
		}
	}

	private void switchOrg(String pk) {
		if (pk != null)
			initUIMainOrgContext(pk.toString());
	}

	private AdminOrgUnitInfo getPersonDep(PersonInfo personInfo)
			throws BOSException {
		FilterInfo filterInfo = new FilterInfo();
		filterInfo.getFilterItems().add(
				new FilterItemInfo("person.id", personInfo.getId().toString()));
		EntityViewInfo viewInfo = new EntityViewInfo();
		viewInfo.setFilter(filterInfo);
		viewInfo.getSelector().add(new SelectorItemInfo("personDep.id"));
		viewInfo.getSelector().add(new SelectorItemInfo("personDep.number"));
		viewInfo.getSelector().add(new SelectorItemInfo("personDep.name"));
		PersonPositionCollection collection = PersonPositionFactory
				.getRemoteInstance().getPersonPositionCollection(viewInfo);
		if ((collection != null) && (collection.size() > 0)) {
			return collection.get(0).getPersonDep();
		}
		return null;
	}

	private void initComboboxItemData(KDComboBox cboCtrl, IDataBase iDatabase,
			EntityViewInfo view) throws BOSException {
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		DataBaseCollection col = iDatabase.getDataBaseCollection(view);
		if (col.size() > 0) {
			for (int i = 0; i < col.size(); i++) {
				model.addElement(col.get(i));
			}
			cboCtrl.setModel(model);
		} else {
			cboCtrl.setModel(model);
		}
	}

	public void loadFields() {
		super.loadFields();
	}

	public void storeFields() {
		super.storeFields();
	}

	public void actionSave_actionPerformed(ActionEvent e) throws Exception {
		if (!isInputValidate()) {
			return;
		}

		EmployeeContractCollection empCols = getAllRowEmployeeContractInfos();
		if (empCols.size() != 0) {
			IEmployeeContract iEmpCont = EmployeeContractFactory
					.getRemoteInstance();
			EmployeeContractState selectedType = (EmployeeContractState) this.cboProcessType
					.getSelectedItem();
			if (selectedType == EmployeeContractState.NEW) {
				this.pks = iEmpCont.addBatchEmployeeContract(empCols);
			} else {
				iEmpCont
						.batchProcessContracts(empCols, selectedType.getValue());
			}
			MsgBox
					.showInfo(
							this,
							EASResource
									.getString("com.kingdee.eas.framework.FrameWorkResource.Msg_Save_OK"));
			this.isSaved = true;
			getUIWindow().close();
		}
	}

	private boolean isInputValidate() throws EmployeeException {
		int i = 0;
		for (int size = this.tblContract.getRowCount(); i < size; i++) {
			String strLineNum = MessageFormat
					.format(
							EASResource
									.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_BATCH_ERROR"),
							new Object[] { new Integer(i + 1) });

			IRow row = this.tblContract.getRow(i);
			if (row.getCell("contractNo").getValue() == null) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_CANNOT_EMPTY"));
				return false;
			}
			if (row.getCell("person").getValue() == null) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_EMP_CANNOT_EMPTY"));
				return false;
			}
			if (row.getCell("toUnit").getValue() == null) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_TOUNIT_CANNOT_EMPTY"));
				return false;
			}
			if (row.getCell("contractTempletName").getValue() == null) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_TEMPLET_CANNOT_EMPTY"));
				return false;
			}
			if (row.getCell("recordDate").getValue() == null) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_CONTRACT_STARTDATE_NOT_NULL"));
				return false;
			}
			if (row.getCell("effectDate").getValue() == null) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_CONTRACT_EFFECTDATE_NOT_NULL"));
				return false;
			}

			Date dtEffectDate = (Date) row.getCell("effectDate").getValue();

			Date dtEndDate = null;
			if (row.getCell("endDate").getValue() != null) {
				dtEndDate = (Date) row.getCell("endDate").getValue();
				if (DateTimeUtils.dayAfter(dtEffectDate, dtEndDate)) {
					MsgBox
							.showInfo(strLineNum
									+ EASResource
											.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_EFFECTDATE_NOT_DY_ENDDATE"));
					return false;
				}
			}

			if ((EmployeeContractState) this.cboProcessType.getSelectedItem() == EmployeeContractState.END) {
				if (row.getCell("endDate").getValue() == null) {
					MsgBox
							.showInfo(strLineNum
									+ EASResource
											.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_CONTRACT_ENDDATE_NOT_NULL"));
					return false;
				}
				Date today = new Date();
				if (DateTimeUtils.dayAfter(dtEndDate, today)) {
					MsgBox
							.showInfo(strLineNum
									+ EASResource
											.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_TODAY_NOT_DY_ENDDATE"));
					return false;
				}
			}

			if ((EmployeeContractState) this.cboProcessType.getSelectedItem() == EmployeeContractState.FREE) {
				if (row.getCell("freeDate").getValue() == null) {
					MsgBox
							.showInfo(strLineNum
									+ EASResource
											.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_CONTRACT_FREEDATE_NOT_NULL"));
					return false;
				}
				Date dtFreeDate = (Date) row.getCell("freeDate").getValue();
				Date today = new Date();
				if (DateTimeUtils.dayAfter(dtFreeDate, today)) {
					MsgBox
							.showInfo(strLineNum
									+ EASResource
											.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEECONTRACT_TODAY_NOT_DY_FREEDATE"));
					return false;
				}
			}
			EmployeeContractState selectedType = (EmployeeContractState) this.cboProcessType
					.getSelectedItem();
			if ((selectedType != EmployeeContractState.NEW)
					&& (selectedType != EmployeeContractState.CHANGE)
					&& (selectedType != EmployeeContractState.RESUME)) {
				continue;
			}
			if ((ContractLimitTypeEnum.FIXED_LIMIT.equals(row.getCell(
					"contractLimitType").getValue()))
					&& (row.getCell("endDate").getValue() == null)) {
				MsgBox
						.showInfo(strLineNum
								+ EASResource
										.getString("com.kingdee.eas.hr.emp.EmployeeResource.CONTRACT_LIMIT_MUST_ENDDATE"));
				return false;
			}
			if ((!ContractLimitTypeEnum.NO_FIXED_LIMIT.equals(row.getCell(
					"contractLimitType").getValue()))
					|| (row.getCell("endDate").getValue() == null)) {
				continue;
			}
			MsgBox
					.showInfo(strLineNum
							+ EASResource
									.getString("com.kingdee.eas.hr.emp.EmployeeResource.CONTRACT_NO_LIMIT_NO_ENDDATE"));
			return false;
		}

		return true;
	}

	public void actionDelete_actionPerformed(ActionEvent e) throws Exception {
		this.tblContract
				.removeRow(KDTableUtil.getSelectedRow(this.tblContract));
	}

	public void actionInsert_actionPerformed(ActionEvent e) throws Exception {
		IRow curRow = this.tblContract.addRow();
		curRow.getCell("recordDate").setValue(new Date());
		curRow.getCell("effectDate").setValue(new Date());
		curRow.getCell("freeDate").setValue(null);
		curRow.getCell("endDate").setValue(null);
		curRow.getCell("continuousSignedCount").setValue(new Integer(0));

		if (this.isExistCodingRule) {
			curRow.getCell("contractNo").setValue(
					getRuleCodingNumber(this.iCodingRuleManager, this.newInfo,
							this.appOUID));
		}
	}

	public void onLoad() throws Exception {
		this.isStrideHRO = HRParamUtil.getParamOfHR(null, "IS_CONTRACT_ALLHR",
				null);

		this.isShowLongName = HRParamUtil.getParamOfHR(null, "IS_CONTRACT_003",
				null);

		if (getUIContext().get("currentHRO") != null) {
			switchOrg(getUIContext().get("currentHRO").toString());
		}

		this.appOUID = getCurrentCU().getId().toString();

		if (this.iCodingRuleManager.isExist(this.newInfo, this.appOUID)) {
			this.isExistCodingRule = true;
		}
		if ((getUIContext().get("isBatchProcess") != null)
				&& (getUIContext().get("isBatchProcess").toString().equals("1"))) {
			this.isBatchProcess = true;
		}

		super.onLoad();

		((KDTTransferAction) this.tblContract.getActionMap().get("Paste"))
				.setPasteMode(2);

		this.tblContract.setAfterAction(new BeforeActionListener() {
			public void beforeAction(BeforeActionEvent e) {
				if (e.getType() == 5) {
					if (BatchContractEditUI.this.tblContract.getSelectManager()
							.size() > 0) {
						int colindex = BatchContractEditUI.this.tblContract
								.getSelectManager().get().getBeginCol();
						int rowindex = BatchContractEditUI.this.tblContract
								.getSelectManager().get().getBeginRow();
						if (colindex == BatchContractEditUI.this.tblContract
								.getColumn("contSrvLimit").getColumnIndex()) {
							BatchContractEditUI.this.tblContract.getRow(
									rowindex).getCell(colindex).setValue(null);
							e.setCancel(true);
						}
					}
				}
			}
		});
		this.tblContract
				.addPropertyChangeListener(new PropertyChangeListener() {
					public void propertyChange(PropertyChangeEvent e) {
						e.getPropertyName();
					}
				});
		setTableCellEditor();

		if (this.isBatchProcess) {
			int size = this.cboProcessType.getItemCount();
			for (int i = size - 1; i >= 0; i--) {
				EmployeeContractState item = (EmployeeContractState) this.cboProcessType
						.getItemAt(i);
				if ((item.getValue() != 0) && (item.getValue() != 1))
					continue;
				this.cboProcessType.removeItemAt(i);
			}

			if ((getUIContext().get("hasHisBatchProcess") != null)
					&& (((Boolean) getUIContext().get("hasHisBatchProcess"))
							.booleanValue())) {
				this.cboProcessType.setSelectedIndex(0);
				this.cboProcessType.setEnabled(false);
			}
			loadProcessContractsToTable();
		} else {
			this.cboProcessType.setEnabled(false);
			loadEmployeeContractToTable();
		}

		Object obj = this.cboProcessType.getSelectedItem();
		if ((EmployeeContractState.RESUME.equals(obj))
				|| (EmployeeContractState.NEW.equals(obj))) {
			refixAllOldContractLimit();
		}

		if ((EmployeeContractState.RESUME.equals(obj))
				|| (EmployeeContractState.CHANGE.equals(obj))) {
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(false);
			this.tHelper.getHideColumn().remove("contractNoOld");
		} else {
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(true);
			this.tHelper.getHideColumn().add("contractNoOld");
		}

		this.tblContract.checkParsed();
		KDTSortManager sortManager = new KDTSortManager(this.tblContract);
		for (int i = 0; i < this.tblContract.getColumnCount(); i++) {
			this.tblContract.getColumn(i).setSortable(true);
		}
		sortManager.setSortAuto(true);

		this.tblContract.getColumn("toUnitAddress").getStyleAttributes()
				.setLocked(false);
		this.tblContract.getColumn("toUnitAddress").getStyleAttributes()
				.setBackground(this.CAN_INPUT_COLOR);
	}

	protected void tblContract_tableSelectChanged(KDTSelectEvent e)
			throws Exception {
		super.tblContract_tableSelectChanged(e);
		int selCol = e.getSelectBlock().getBeginCol();
		for (int i = e.getSelectBlock().getBeginRow(); i <= e.getSelectBlock()
				.getEndRow(); i++) {
			if ((i == -1)
					|| (this.tblContract.getColumnIndex("toUnit") != selCol))
				continue;
			Object objIsInAdmin = this.tblContract.getRow(i).getCell(
					"isInAdmin").getValue();
			if (new Boolean(true).equals(objIsInAdmin)) {
				this.tblContract.getRow(i).getCell("toUnit").setEditor(
						new KDTDefaultCellEditor(this.promptToUnitBox));
			} else {
				this.tblContract.getRow(i).getCell("toUnit").setEditor(
						new KDTDefaultCellEditor(new KDTextField()));
			}
		}
	}

	private HROrgUnitInfo getCurrentHRO() {
		if (getMainOrgContext() == null) {
			return SysContext.getSysContext().getCurrentHRUnit();
		}

		if (FrameWorkUtils.getCurrentOrgUnit(getMainOrgContext(),
				OrgType.ControlUnit) != null) {
			return (HROrgUnitInfo) FrameWorkUtils.getCurrentOrgUnit(
					getMainOrgContext(), OrgType.HRO);
		}

		return SysContext.getSysContext().getCurrentHRUnit();
	}

	private CtrlUnitInfo getCurrentCU() {
		if (getMainOrgContext() == null) {
			return SysContext.getSysContext().getCurrentCtrlUnit();
		}

		if (FrameWorkUtils.getCurrentOrgUnit(getMainOrgContext(),
				OrgType.ControlUnit) != null) {
			return (CtrlUnitInfo) FrameWorkUtils.getCurrentOrgUnit(
					getMainOrgContext(), OrgType.ControlUnit);
		}

		return SysContext.getSysContext().getCurrentCtrlUnit();
	}

	protected void initWorkButton() {
		super.initWorkButton();

		this.tblContract.checkParsed();
		this.btnSave.setIcon(EASResource.getIcon("imgTbtn_save"));
		this.btnSelectCopy.setIcon(EASResource.getIcon("imgTbtn_electcopy"));

		EmployeeClientUtils.initTableBtn(this.btnInsert, this.btnDelete);
		this.btnInsert.setEnabled(true);
		this.btnDelete.setEnabled(true);
		this.btnSave.setEnabled(true);

		if (this.isBatchProcess) {
			this.btnInsert.setVisible(false);
			this.btnDelete.setVisible(false);
		}
	}

	private void loadContractTempletComboData(String selectedTypeId)
			throws EASBizException, BOSException {
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		IContractTemplet iContemp = ContractTempletFactory.getRemoteInstance();

		FilterInfo filter = getD1FilterOfCT();
		FilterInfo filter2 = new FilterInfo();
		filter2.getFilterItems().add(
				new FilterItemInfo("contractType.id", selectedTypeId));
		filter = HRUtil.customMergeFilter(filter, filter2, "AND");

		EntityViewInfo viewInfo = new EntityViewInfo();
		viewInfo.setFilter(filter);
		ContractTempletCollection infos = iContemp
				.getContractTempletCollection(viewInfo);

		for (int i = 0; i < infos.size(); i++) {
			model.addElement(infos.get(i));
		}
		this.cboContractTemplet.setModel(model);
		this.tblContract.getColumn("contractTempletName").setEditor(
				new KDTDefaultCellEditor(this.cboContractTemplet));
	}

	private FilterInfo getD1FilterOfCT() throws EASBizException, BOSException {
		FilterInfo fiTem = ContractTempletFactory.getRemoteInstance()
				.getDatabaseDFilter(new ObjectUuidPK(getCurrentCU().getId()),
						"id", "adminCU.id");

		return fiTem;
	}

	private void loadEmployeeContractToTable() throws Exception {

		PersonCollection personInfos = (PersonCollection) getUIContext().get(
				"personInfos");

		List<PersonInfo> list = new ArrayList<PersonInfo>();

		for (int i = 0; i < personInfos.size(); i++) {
			list.add(personInfos.get(i));
		}

		Collections.sort(list, new Comparator<PersonInfo>() {

			public int compare(PersonInfo o1, PersonInfo o2) {
				return o1.getNumber().compareTo(o2.getNumber());
			}
		});
		ContractTempletCollection contractTempletInfos = (ContractTempletCollection) getUIContext()
				.get("contractTempletInfos");
		AdminOrgUnitInfo toUnitInfo = null;
		String toUnit = "";

		if ((getUIContext().get("isInAdmin") != null)
				&& (((Boolean) getUIContext().get("isInAdmin")).booleanValue()))
			toUnitInfo = (AdminOrgUnitInfo) getUIContext().get("toUnit");
		else {
			toUnit = getUIContext().get("toUnit").toString();
		}
		PersonInfo delegatePersonInfo = (PersonInfo) getUIContext().get(
				"delegatePerson");
		Date recordDate = (Date) getUIContext().get("recordDate");
		Date effectDate = (Date) getUIContext().get("effectDate");
		Date freeDate = (Date) getUIContext().get("freeDate");
		Date endDate = (Date) getUIContext().get("endDate");
		String unitAddress = (String) getUIContext().get("unitAddress");

		int conSize = contractTempletInfos.size();
		int personSize = list.size();
		for (int j = 0; j < conSize; j++)
			for (int i = 0; i < personSize; i++)
				addNewContractToTable(list.get(i), contractTempletInfos
						.get(j), toUnitInfo, toUnit, delegatePersonInfo,
						recordDate, effectDate, freeDate, endDate, unitAddress);
	}

	private void addNewContractToTable(PersonInfo personInfo,
			ContractTempletInfo contractTempletInfo,
			AdminOrgUnitInfo toUnitInfo, String toUnit,
			PersonInfo delegatePersonInfo, Date recordDate, Date effectDate,
			Date freeDate, Date endDate, String unitAddress) throws Exception {
		IRow curRow = this.tblContract.addRow();
		curRow.getCell("person").setValue(personInfo);

		curRow.getCell("empNumber").setValue(personInfo.getNumber());

		AdminOrgUnitInfo unitInfo = (AdminOrgUnitInfo) personInfo
				.get("primaryAdminOrg");
		curRow.getCell("empUnit").setValue(unitInfo);

		PositionInfo posInfo = (PositionInfo) personInfo.get("primaryPosition");
		curRow.getCell("empPosition").setValue(posInfo);

		if ((getUIContext().get("isInAdmin") != null)
				&& (((Boolean) getUIContext().get("isInAdmin")).booleanValue()))
			curRow.getCell("toUnit").setValue(toUnitInfo);
		else {
			curRow.getCell("toUnit").setValue(toUnit);
		}
		curRow.getCell("isInAdmin").setValue(getUIContext().get("isInAdmin"));

		curRow.getCell("toUnitAddress").setValue(unitAddress);

		curRow.getCell("delegatePerson").setValue(delegatePersonInfo);

		curRow.getCell("contractTypeName").setValue(
				contractTempletInfo.getContractType());

		curRow.getCell("contractTempletName").setValue(contractTempletInfo);
		curRow.getCell("recordDate").setValue(recordDate);
		curRow.getCell("effectDate").setValue(effectDate);
		curRow.getCell("freeDate").setValue(freeDate);
		curRow.getCell("endDate").setValue(endDate);
		curRow.getCell("thirdUnitName").setValue(
				getUIContext().get("thirdUnitName"));
		curRow.getCell("thirdDelegatePerson").setValue(
				getUIContext().get("thirdDelegatePerson"));
		curRow.getCell("thirdUnitAddress").setValue(
				getUIContext().get("thirdUnitAddress"));
		curRow.getCell("contractLimitType").setValue(
				getUIContext().get("contractLimitType"));
		curRow.getCell("employeeClassify").setValue(
				personInfo.get("employeeClassify"));
		curRow.getCell("contractLimitAuto").setValue(
				getUIContext().get("contractLimitAuto"));
		if (this.isExistCodingRule) {
			curRow.getCell("contractNo").setValue(
					getRuleCodingNumber(this.iCodingRuleManager, this.newInfo,
							this.appOUID));
		}

		if (contractTempletInfo.getContractType().isIsLaborContract()) {
			curRow.getCell("isContinuousSigned")
					.setValue(Boolean.valueOf(true));
			curRow.getCell("continuousSignedCount").setValue(new Integer(1));
			StyleAttributes styleAttributes = curRow.getCell(
					"isContinuousSigned").getStyleAttributes();
			styleAttributes.setLocked(false);
			styleAttributes.setBackground(this.CAN_INPUT_COLOR);
			styleAttributes = curRow.getCell("continuousSignedCount")
					.getStyleAttributes();
			styleAttributes.setLocked(false);
			styleAttributes.setBackground(this.CAN_INPUT_COLOR);
		} else {
			curRow.getCell("isContinuousSigned").setValue(
					Boolean.valueOf(false));
			curRow.getCell("continuousSignedCount").setValue(new Integer(0));
			StyleAttributes styleAttributes = curRow.getCell(
					"isContinuousSigned").getStyleAttributes();
			styleAttributes.setLocked(true);
			styleAttributes.setBackground(this.CANNOT_INPUT_COLOR);
			styleAttributes = curRow.getCell("continuousSignedCount")
					.getStyleAttributes();
			styleAttributes.setLocked(true);
			styleAttributes.setBackground(this.CANNOT_INPUT_COLOR);
		}
	}

	private String getRuleCodingNumber(ICodingRuleManager iCodingRuleManager,
			EmployeeContractInfo newInfo, String appOUID) {
		String curCodingRuleNumber = "";
		try {
			if (this.isExistCodingRule) {
				curCodingRuleNumber = iCodingRuleManager.readNumber(newInfo,
						appOUID);
			}
		} catch (Exception e) {
			handleException(e);
		}
		return curCodingRuleNumber;
	}

	private void initCboTypeEvent() {
		this.cboContractTemplet.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
			}
		});
	}

	private DefaultComboBoxModel getContractTempletComboModel(
			String selectedTypeId) throws Exception {
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		IContractTemplet iContemp = ContractTempletFactory.getRemoteInstance();
		ContractTempletCollection infos = iContemp
				.getContractTempletCollection("Select * Where contractType = '"
						+ selectedTypeId + "'");
		if (infos.size() > 0) {
			for (int i = 0; i < infos.size(); i++) {
				model.addElement(infos.get(i));
			}
			return model;
		}
		return null;
	}

	private EmployeeContractCollection getAllRowEmployeeContractInfos()
			throws EASBizException, BOSException {
		EmployeeContractCollection infoCols = new EmployeeContractCollection();
		for (int i = 0; i < this.tblContract.getRowCount(); i++) {
			EmployeeContractInfo info = new EmployeeContractInfo();
			PersonInfo psValue = (PersonInfo) this.tblContract.getRow(i)
					.getCell("person").getValue();
			PersonInfo psInfo = PersonFactory.getRemoteInstance()
					.getPersonInfo(new ObjectUuidPK(psValue.getId()));
			info.setEmployee(psInfo);
			info.setEmpIdentityNum(psInfo.getIdCardNO());
			info.setEmpPassPortNum(psInfo.getPassportNO());
			info.setEmpAddress(psInfo.getAddressTX());

			ContractTempletInfo templetInfo = (ContractTempletInfo) this.tblContract
					.getRow(i).getCell("contractTempletName").getValue();
			info.setContractTemplet(templetInfo);

			String strContractNo = this.tblContract.getRow(i).getCell(
					"contractNo").getValue().toString();
			if ((this.isExistCodingRule) && (!this.isBatchProcess)) {
				strContractNo = templetInfo.getNumber() + strContractNo;
			}
			info.setContractNo(strContractNo);

			if ((this.tblContract.getRow(i).getCell("toUnit").getValue() instanceof AdminOrgUnitInfo)) {
				AdminOrgUnitInfo toUnitInfo = (AdminOrgUnitInfo) this.tblContract
						.getRow(i).getCell("toUnit").getValue();
				if (this.isShowLongName) {
					info.setToUnit(toUnitInfo.getDisplayName());
				} else {
					info.setToUnit(toUnitInfo.getName());
				}
				if (toUnitInfo.getAdminAddress() != null) {
					info.setToUnitAddress(toUnitInfo.getAdminAddress());
				}
			} else {
				info.setToUnit(this.tblContract.getRow(i).getCell("toUnit")
						.getValue().toString());
			}

			Object dgPerson = this.tblContract.getRow(i).getCell(
					"delegatePerson").getValue();
			if (dgPerson != null) {
				info.setDelegatePerson(dgPerson.toString());
			}

			info.setToUnitAddress((String) this.tblContract.getRow(i).getCell(
					"toUnitAddress").getValue());
			info.setRecordDate((Date) this.tblContract.getRow(i).getCell(
					"recordDate").getValue());
			info.setEffectDate((Date) this.tblContract.getRow(i).getCell(
					"effectDate").getValue());
			info.setEndDate((Date) this.tblContract.getRow(i)
					.getCell("endDate").getValue());
			info.setFreeDate((Date) this.tblContract.getRow(i).getCell(
					"freeDate").getValue());

			info.setContractLimit((ContractLimitInfo) this.tblContract
					.getRow(i).getCell("contractLimit").getValue());
			info.setContSerLimit((ContractServerLimitInfo) this.tblContract
					.getRow(i).getCell("contSrvLimit").getValue());
			info.setTestBeginDate((Date) this.tblContract.getRow(i).getCell(
					"testBeginDate").getValue());
			info.setTestEndDate((Date) this.tblContract.getRow(i).getCell(
					"testEndDate").getValue());
			info.setThirdDelegatePerson((String) this.tblContract.getRow(i)
					.getCell("thirdDelegatePerson").getValue());
			info.setThirdUnitName((String) this.tblContract.getRow(i).getCell(
					"thirdUnitName").getValue());
			info.setThirdUnitAddress((String) this.tblContract.getRow(i)
					.getCell("thirdUnitAddress").getValue());
			info.setContractLimitType((ContractLimitTypeEnum) this.tblContract
					.getRow(i).getCell("contractLimitType").getValue());
			info.setIsInAdmin(new Boolean(true).equals(this.tblContract.getRow(
					i).getCell("isInAdmin").getValue()));
			info.setContractLimitAuto((String) this.tblContract.getRow(i)
					.getCell("contractLimitAuto").getValue());
			if (Boolean.TRUE.equals(this.tblContract.getRow(i).getCell(
					"isContinuousSigned").getValue()))
				info.setIsContinuousSigned(true);
			else {
				info.setIsContinuousSigned(false);
			}
			Object countValue = this.tblContract.getRow(i).getCell(
					"continuousSignedCount").getValue();
			if ((countValue instanceof Integer))
				info
						.setContinuousSignedCount(((Integer) countValue)
								.intValue());
			else {
				info.setContinuousSignedCount(0);
			}

			if (this.isBatchProcess) {
				info.setId(BOSUuid.read(this.tblContract.getRow(i).getCell(
						"contractId").getValue().toString()));
			}

			info.setHrOrgUnit(getCurrentHRO());

			info.setCU(getCurrentCU());

			infoCols.add(info);
		}
		return infoCols;
	}

	private void fixContractLimitAuto(int rowIndex, Object effectDate,
			Object endDate) {
		if (rowIndex == -1)
			rowIndex = this.rowID;
		ICell cellLimitAuto = this.tblContract.getRow(rowIndex).getCell(
				"contractLimitAuto");
		cellLimitAuto.setValue(null);
		Object contractLimitType = this.tblContract.getRow(rowIndex).getCell(
				"contractLimitType").getValue();

		if ((ContractLimitTypeEnum.FIXED_LIMIT.equals(contractLimitType))
				&& (effectDate != null) && (endDate != null)) {
			long diftime = ((Date) endDate).getTime()
					- ((Date) effectDate).getTime();

			BigDecimal contractLimit = new BigDecimal("" + diftime).setScale(1)
					.divide(new BigDecimal("31536000000"), 4);

			cellLimitAuto.setValue("" + contractLimit);
		}
	}

	private void fixContractLimitAuto(Object effectDate, Object endDate) {
		fixContractLimitAuto(-1, effectDate, endDate);
	}

	public void actionSelectCopy_actionPerformed(ActionEvent e)
			throws Exception {
		if (this.tblContract.getRowCount() == 0) {
			return;
		}
		KDTSelectBlock sb = null;
		int size = this.tblContract.getSelectManager().size();
		if (size > 0) {
			sb = this.tblContract.getSelectManager().get(0);
			ICell iCell = null;
			int row = sb.getTop();
			int column = sb.getLeft();
			IColumn iColumn = this.tblContract.getColumn(column);
			if (iColumn.getStyleAttributes().isLocked()) {
				return;
			}
			Object value = this.tblContract.getCell(row, column).getValue();
			boolean isContractLimitType = column == this.tblContract.getColumn(
					"contractLimitType").getColumnIndex();
			boolean isEffectDate = column == this.tblContract.getColumn(
					"effectDate").getColumnIndex();
			boolean isEndDate = column == this.tblContract.getColumn("endDate")
					.getColumnIndex();

			for (int i = 0; i < size; i++) {
				sb = this.tblContract.getSelectManager().get(i);
				for (int j = sb.getBeginRow(); j <= sb.getEndRow(); j++) {
					if (this.tblContract.getCell(j, column)
							.getStyleAttributes().isLocked())
						continue;
					iCell = this.tblContract.getCell(j, column);
					iCell.setValue(value);
					if (isContractLimitType) {
						refreshStatusByContractLimitType(j, value);
					}
					if ((!isEffectDate) && (!isEndDate))
						continue;
					Object effectDate = this.tblContract.getRow(j).getCell(
							"effectDate").getValue();
					Object endDate = this.tblContract.getRow(j).getCell(
							"endDate").getValue();
					fixContractLimitAuto(j, effectDate, endDate);
				}
			}
		}
	}

	private void lockTable() {
		int i = 0;
		for (int size = this.tblContract.getColumnCount(); i < size; i++) {
			this.tblContract.getColumn(i).getStyleAttributes().setBackground(
					this.CANNOT_INPUT_COLOR);
			this.tblContract.getColumn(i).getStyleAttributes().setLocked(true);
		}
	}

	private void lockColumnWithKey(String columnKey) {
		this.tblContract.getColumn(columnKey).getStyleAttributes()
				.setBackground(this.CANNOT_INPUT_COLOR);
		this.tblContract.getColumn(columnKey).getStyleAttributes().setLocked(
				true);
	}

	private void unLockColumnWithKey(String columnKey, boolean isRequired) {
		Color cr = this.CAN_INPUT_COLOR;
		if (isRequired) {
			cr = this.MUST_INPUT_COLOR;
		}
		this.tblContract.getColumn(columnKey).getStyleAttributes()
				.setBackground(cr);
		this.tblContract.getColumn(columnKey).getStyleAttributes().setLocked(
				false);
	}

	private Map getContinuousContractPersonId() {
		Map personMap = null;
		int rowCount = this.tblContract.getRowCount();
		if (rowCount > 0) {
			personMap = new HashMap();
			for (int i = 0; i < rowCount; i++) {
				IRow row = this.tblContract.getRow(i);
				Object contractType = row.getCell("contractTypeName")
						.getValue();
				if ((contractType == null)
						|| (!(contractType instanceof ContractTypeInfo))
						|| (!((ContractTypeInfo) contractType)
								.isIsLaborContract())
						|| (!ContractLimitTypeEnum.FIXED_LIMIT.equals(row
								.getCell("contractLimitType").getValue()))) {
					continue;
				}
				PersonInfo personInfo = (PersonInfo) row.getCell("person")
						.getValue();
				personMap.put(personInfo.getId().toString(), personInfo);
			}
		}

		return personMap;
	}

	private void checkContinuousContracts() throws BOSException {
		Map personMap = getContinuousContractPersonId();
		if ((personMap == null) || (personMap.size() == 0)) {
			return;
		}

		Set personSet = personMap.keySet();
		List personIdList = new ArrayList();
		Iterator it = personSet.iterator();
		while (it.hasNext()) {
			personIdList.add(it.next());
		}

		IEmployeeContract contractBean = EmployeeContractFactory
				.getRemoteInstance();
		Map map = contractBean.getContinuousContracts(personIdList);
		if ((map != null) && (map.size() > 0)) {
			String info = EASResource
					.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_CONTRACT_COUNT");
			info = MessageFormat.format(info, new Object[] { new Integer(map
					.size()) });

			String info2 = EASResource
					.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_CONTRACT_MORE_THAN_TWO");
			StringBuffer detailedInfo = new StringBuffer();
			Iterator iterator = map.keySet().iterator();
			boolean first = true;
			while (iterator.hasNext()) {
				String id = (String) iterator.next();
				List contractList = (List) map.get(id);
				if (first)
					first = false;
				else {
					detailedInfo.append("\n\n");
				}
				detailedInfo.append(MessageFormat.format(info2, new Object[] {
						((PersonInfo) personMap.get(id)).getNumber(),
						((PersonInfo) personMap.get(id)).getName() }));

				for (int i = 0; i < contractList.size(); i++) {
					EmployeeContractInfo contractInfo = (EmployeeContractInfo) contractList
							.get(i);
					detailedInfo.append("\n");
					detailedInfo.append(contractInfo.getContractNo() + " ");
					detailedInfo.append(contractInfo.getEffectDate() + " ");
					if (contractInfo.getEndDate() != null) {
						detailedInfo.append(contractInfo.getEndDate() + " ");
					}
					detailedInfo.append(contractInfo.getToUnit());
				}
			}
			MsgBox.showDetailAndOK(this, info, detailedInfo.toString(), 1);

			int count = this.tblContract.getRowCount();
			for (int i = 0; i < count; i++) {
				IRow row = this.tblContract.getRow(i);
				PersonInfo personInfo = (row.getCell("person") instanceof PersonInfo) ? (PersonInfo) row
						.getCell("person")
						: null;

				if (personInfo == null) {
					continue;
				}
				if (map.get(personInfo.getId()) != null) {
					row.getCell("isContinuousSigned").setValue(
							Boolean.valueOf(true));
					List list = (List) map.get(personInfo.getId());
					row.getCell("continuousSignedCount").setValue(
							new Integer(list.size()));
				}
			}

		}

		StringBuffer oql = new StringBuffer();
		oql
				.append("SELECT id, person.number, person.name WHERE person.id IN (");
		for (int i = 0; i < personIdList.size(); i++) {
			oql.append("'" + personIdList.get(i) + "'");
			if (i != personIdList.size() - 1) {
				oql.append(", ");
			}
		}
		oql.append(") AND joinGroupYears >= 10.0");
		IPersonPosition positionBean = PersonPositionFactory
				.getRemoteInstance();
		PersonPositionCollection positionColl = positionBean
				.getPersonPositionCollection(oql.toString());
		if (positionColl.size() > 0) {
			String info = EASResource
					.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE_COUNT");
			info = MessageFormat.format(info, new Object[] { new Integer(
					positionColl.size()) });

			String info2 = EASResource
					.getString("com.kingdee.eas.hr.emp.EmployeeResource.EMPLOYEE");
			StringBuffer detailedInfo = new StringBuffer();
			for (int i = 0; i < positionColl.size(); i++) {
				detailedInfo.append(MessageFormat.format(info2, new Object[] {
						positionColl.get(i).getPerson().getNumber(),
						positionColl.get(i).getPerson().getName() }));

				if (i != positionColl.size() - 1) {
					detailedInfo.append("\n");
				}
			}
			MsgBox.showDetailAndOK(this, info, detailedInfo.toString(), 1);
		}
	}

	protected void cboProcessType_itemStateChanged(ItemEvent e)
			throws Exception {
		loadProcessContractsToTable();

		Object obj = this.cboProcessType.getSelectedItem();
		if ((EmployeeContractState) obj == EmployeeContractState.RESUME) {
			lockTable();
			unLockColumnWithKey("contractLimit", false);
			unLockColumnWithKey("contSrvLimit", false);
			unLockColumnWithKey("recordDate", true);
			unLockColumnWithKey("effectDate", true);
			unLockColumnWithKey("endDate", false);
			unLockColumnWithKey("contractLimitType", false);
			unLockColumnWithKey("isContinuousSigned", false);
			unLockColumnWithKey("continuousSignedCount", false);
			unLockColumnWithKey("toUnitAddress", false);
			if (!this.isExistCodingRule) {
				clearAllOldContractNo();

				unLockColumnWithKey("contractNo", true);
			}
			refixAllOldContractLimit();
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(false);
			this.tHelper.getHideColumn().remove("contractNoOld");
		} else if ((EmployeeContractState) obj == EmployeeContractState.CHANGE) {
			lockTable();
			unLockColumnWithKey("toUnit", true);
			unLockColumnWithKey("isInAdmin", true);
			unLockColumnWithKey("delegatePerson", false);
			unLockColumnWithKey("contractTypeName", true);
			unLockColumnWithKey("contractTempletName", true);
			unLockColumnWithKey("contractLimit", false);
			unLockColumnWithKey("contSrvLimit", false);
			unLockColumnWithKey("recordDate", true);
			unLockColumnWithKey("effectDate", true);
			unLockColumnWithKey("endDate", false);
			unLockColumnWithKey("thirdUnitName", false);
			unLockColumnWithKey("thirdUnitAddress", false);
			unLockColumnWithKey("thirdDelegatePerson", false);
			unLockColumnWithKey("contractLimitType", false);
			unLockColumnWithKey("isContinuousSigned", false);
			unLockColumnWithKey("continuousSignedCount", false);
			unLockColumnWithKey("toUnitAddress", false);
			if (!this.isExistCodingRule) {
				clearAllOldContractNo();
				unLockColumnWithKey("contractNo", true);
			}
			refixAllOldContractLimit();
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(false);
			this.tHelper.getHideColumn().remove("contractNoOld");
		} else if ((EmployeeContractState) obj == EmployeeContractState.END) {
			lockTable();
			unLockColumnWithKey("endDate", true);
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(true);
			this.tHelper.getHideColumn().add("contractNoOld");
		} else if ((EmployeeContractState) obj == EmployeeContractState.FREE) {
			lockTable();
			unLockColumnWithKey("freeDate", true);
			this.tblContract.getColumn("contractNoOld").getStyleAttributes()
					.setHided(true);
			this.tHelper.getHideColumn().add("contractNoOld");
		}

		if (this.theFirst) {
			checkContinuousContracts();
			this.theFirst = false;
		}
	}

	private void clearAllOldContractNo() {
		int i = 0;
		for (int size = this.tblContract.getRowCount(); i < size; i++) {
			this.tblContract.getRow(i).getCell("contractNo").setValue(null);
		}
	}

	private void refixAllOldContractLimit() {
		int i = 0;
		for (int size = this.tblContract.getRowCount(); i < size; i++) {
			Object effectDate = this.tblContract.getRow(i)
					.getCell("effectDate").getValue();
			Object endDate = this.tblContract.getRow(i).getCell("endDate")
					.getValue();
			fixContractLimitAuto(i, effectDate, endDate);

			refreshStatusByContractLimitType(i, this.tblContract.getRow(i)
					.getCell("contractLimitType").getValue());
		}
	}

	private void refreshStatusByContractLimitType(int rowIndex,
			Object contractLimitType) {
		if (rowIndex == -1)
			rowIndex = this.rowID;
		if (ContractLimitTypeEnum.FIXED_LIMIT.equals(contractLimitType)) {
			this.tblContract.getRow(rowIndex).getCell("endDate")
					.getStyleAttributes().setLocked(false);
			this.tblContract.getRow(rowIndex).getCell("endDate")
					.getStyleAttributes().setBackground(this.MUST_INPUT_COLOR);
		} else {
			EmployeeContractState selectedType = (EmployeeContractState) this.cboProcessType
					.getSelectedItem();
			if ((selectedType == EmployeeContractState.NEW)
					|| (selectedType == EmployeeContractState.CHANGE)
					|| (selectedType == EmployeeContractState.RESUME)) {
				this.tblContract.getRow(rowIndex).getCell("endDate")
						.getStyleAttributes().setLocked(true);
				this.tblContract.getRow(rowIndex).getCell("endDate")
						.getStyleAttributes().setBackground(
								this.CANNOT_INPUT_COLOR);
				this.tblContract.getRow(rowIndex).getCell("contractLimitAuto")
						.setValue(null);
				this.tblContract.getRow(rowIndex).getCell("endDate").setValue(
						null);
			}
		}
	}

	private void refreshStatusByContractLimitType(Object contractLimitType) {
		refreshStatusByContractLimitType(-1, contractLimitType);
	}

	private void loadProcessContractsToTable() throws EASBizException,
			BOSException, SQLException {
		StringBuffer sb = (StringBuffer) getUIContext().get(
				"selectedContractIds");
		if (sb.toString().equals("")) {
			return;
		}
		Object obj = this.cboProcessType.getSelectedItem();
		this.tblContract.removeRows();
		String[] idsList = sb.toString().split(",");
		IRowSet rs = EmployeeContractFactory.getRemoteInstance()
				.getProcessContractsDataByIds(sb);
		int i = 0;
		for (int size = idsList.length; i < size; i++) {
			String strId = idsList[i].substring(1, idsList[i].length() - 1);
			rs.beforeFirst();
			while (rs.next()) {
				if (!rs.getString("id").equals(strId)) {
					continue;
				}

				PersonInfo perInfo = new PersonInfo();
				perInfo.setId(BOSUuid.read(rs.getString("employee.id")));
				perInfo.setName(rs.getString("employee.name"));
				perInfo.setNumber(rs.getString("employee.number"));

				AdminOrgUnitInfo unitInfo = new AdminOrgUnitInfo();
				unitInfo.setId(BOSUuid.read(rs.getString("empAdminUnit.id")));
				unitInfo.setName(rs.getString("empAdminUnit.name"));

				PositionInfo posInfo = null;
				if (rs.getString("empPosition.id") != null) {
					posInfo = new PositionInfo();
					posInfo.setId(BOSUuid.read(rs.getString("empPosition.id")));
					posInfo.setName(rs.getString("empPosition.name"));
				}

				ContractTypeInfo typeInfo = new ContractTypeInfo();
				typeInfo.setId(BOSUuid.read(rs.getString("contractType.id")));
				typeInfo.setName(rs.getString("contractType.name"));
				typeInfo.setIsLaborContract(rs
						.getBoolean("contractType.isLaborContract"));

				ContractTempletInfo templetInfo = new ContractTempletInfo();
				templetInfo.setId(BOSUuid.read(rs
						.getString("contractTemplet.id")));
				templetInfo.setName(rs.getString("contractTemplet.name"));
				templetInfo.setNumber(rs.getString("contractTemplet.number"));

				ContractLimitInfo contLimitInfo = new ContractLimitInfo();

				contLimitInfo.setName("");
				if (rs.getString("ContractLimit.id") != null) {
					contLimitInfo.setId(BOSUuid.read(rs
							.getString("ContractLimit.id")));
					contLimitInfo.setName(rs.getString("ContractLimit.name"));
				}

				ContractServerLimitInfo contSrvLimitInfo = new ContractServerLimitInfo();

				contSrvLimitInfo.setName("");
				if (rs.getString("ContractServerLimit.id") != null) {
					contSrvLimitInfo.setId(BOSUuid.read(rs
							.getString("ContractServerLimit.id")));
					contSrvLimitInfo.setName(rs
							.getString("ContractServerLimit.name"));
				}

				IRow curRow = this.tblContract.addRow();
				curRow.getCell("contractId").setValue(rs.getString("id"));
				curRow.getCell("contractNoOld").setValue(
						rs.getString("contractNo"));
				curRow.getCell("contractNo").setValue(
						rs.getString("contractNo"));
				curRow.getCell("person").setValue(perInfo);
				curRow.getCell("empNumber").setValue(
						rs.getString("employee.number"));
				curRow.getCell("empUnit").setValue(unitInfo);
				curRow.getCell("empPosition").setValue(posInfo);
				curRow.getCell("toUnit").setValue(rs.getString("toUnit"));
				curRow.getCell("toUnitAddress").setValue(
						rs.getString("toUnitAddress"));
				curRow.getCell("isInAdmin").setValue(new Boolean(true));
				curRow.getCell("delegatePerson").setValue(
						rs.getString("delegatePerson"));
				curRow.getCell("contractTypeName").setValue(typeInfo);
				curRow.getCell("contractTempletName").setValue(templetInfo);
				curRow.getCell("isInAdmin").setValue(
						new Boolean(rs.getBoolean("isInAdmin")));

				if ((EmployeeContractState) obj == EmployeeContractState.RESUME) {
					curRow.getCell("recordDate")
							.setValue(rs.getDate("endDate"));
					curRow.getCell("effectDate")
							.setValue(rs.getDate("endDate"));
				} else {
					curRow.getCell("recordDate").setValue(
							rs.getDate("recordDate"));
					curRow.getCell("effectDate").setValue(
							rs.getDate("effectDate"));
				}

				curRow.getCell("freeDate").setValue(rs.getDate("freeDate"));
				curRow.getCell("endDate").setValue(rs.getDate("endDate"));
				curRow.getCell("contractLimit").setValue(contLimitInfo);
				curRow.getCell("contSrvLimit").setValue(contSrvLimitInfo);
				curRow.getCell("testBeginDate").setValue(
						rs.getDate("testBeginDate"));
				curRow.getCell("testEndDate").setValue(
						rs.getDate("testEndDate"));
				curRow.getCell("thirdUnitName").setValue(
						rs.getString("thirdUnitName"));
				curRow.getCell("thirdDelegatePerson").setValue(
						rs.getString("thirdDelegatePerson"));
				curRow.getCell("thirdUnitAddress").setValue(
						rs.getString("thirdUnitAddress"));
				curRow.getCell("employeeClassify").setValue(
						rs.getString("employeeClassify.name"));
				curRow.getCell("contractLimitAuto").setValue(
						rs.getString("contractLimitAuto"));
				if ("1".equals(rs.getString("contractLimitType"))) {
					curRow.getCell("contractLimitType").setValue(
							ContractLimitTypeEnum.FIXED_LIMIT);
				}
				if ("2".equals(rs.getString("contractLimitType"))) {
					curRow.getCell("contractLimitType").setValue(
							ContractLimitTypeEnum.NO_FIXED_LIMIT);
				}
				if ("3".equals(rs.getString("contractLimitType"))) {
					curRow.getCell("contractLimitType").setValue(
							ContractLimitTypeEnum.COMPLETE_WORK_TYPE);
				}
				curRow.getCell("isContinuousSigned").setValue(
						Boolean.valueOf(rs.getBoolean("isContinuousSigned")));
				curRow.getCell("continuousSignedCount").setValue(
						new Integer(rs.getInt("continuousSignedCount")));

				updateRowStringEmpty2Null(curRow,
						new String[] { "delegatePerson" });
			}
		}
	}

	private void updateRowStringEmpty2Null(IRow row, String[] columnNames) {
		for (int i = 0; i < columnNames.length; i++) {
			String columnName = columnNames[i];
			Object value = row.getCell(columnName).getValue();
			System.out.println("is:" + value);
			if ((value == null) || (!(value instanceof String))
					|| (!StringUtils.isEmpty((String) value)))
				continue;
			row.getCell(columnName).setValue(null);
		}
	}
}